<template>
  <div class="loginContainer">
    <el-form 
      class="loginForm"
      :model="loginForm" 
      ref="loginForm" 
      :inline="false" 
      size="medium"
      :rules="loginRules"
    >
      <el-form-item>
        <div class="loginTitle">系统登录</div>
      </el-form-item>
      <el-form-item prop="username">
        <el-input v-model="loginForm.username" placeholder="请输入用户名"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input v-model="loginForm.password" placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-form-item prop="code">
        <el-row :gutter="10">
          <el-col :span="16">
            <el-input v-model="loginForm.code" placeholder="请输入验证码" clearable @change=""></el-input>
          </el-col>
          <el-col :span="8">
            <el-input v-model="loginForm.code" placeholder="验证码" clearable @change=""></el-input>
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-button class="btn" type="primary" @click="commitBtn">登录</el-button>
          </el-col>
          <el-col :span="12">
            <el-button class="btn" @click="reseBtn">重置</el-button>
          </el-col>
        </el-row>
        
      </el-form-item>
    </el-form>
    
  </div>
</template>

<script>
  export default {
    name: 'login',
    data () {
      return {
        loginForm: {
          username: '',
          password: '' ,
          code: ''
        },
        loginRules: {
          username: [
            {
              required: true,
              trigger: 'change',
              message: '请输入用户名'
            }
          ],
          password: [
            {
              required: true,
              trigger: 'change',
              message: '请输入密码'
            }
          ],
          code: [
            {
              required: true,
              tirgger: 'change',
              message: '请输入验证码'
            }
          ]
        }
      }
    },
    methods: {
      commitBtn() {
        this.$refs.loginForm.validate(val => {
          if (val) {
            console.log(val);
          }
        })
      },
      reseBtn() {
        this.$refs['loginForm'].resetFields();
      }
    },
  }

</script>

<style scoped>
.loginContainer {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.loginForm {
  width: 350px;
  height: 300px;
  border-radius: 10px;
  box-shadow: 0 0 25px #cac6c6;
  padding: 20px 35px;
}
.loginTitle {
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 600;
  font-size: 24px;
}
.btn {
  width: 100%;
}
</style>